<?php defined('SYSPATH') or die('No direct script access.');
 
class Model_ForDB extends Model
{
    
 
    /**
     * Get all articles
     * @return array
     */
    public function getProducts()
    {
               
        $sql=<<<here
SELECT 
        produkt.id AS id,
        produkt.produkt_name AS name,
        produkt.product_price AS price,
        catalog_id.catalog AS catalog,
        company_id.company_name AS company,
        id_about.about AS about,
        prod_id.product_name AS prodgroup

        
FROM 
        produkt,
        catalog_id,
        company_id,
        id_about,
        prod_id
         
        

WHERE 
        catalog_id.id_number =produkt.catalog_id
    AND company_id.id_number=produkt.company_id
    AND id_about.id_number=produkt.id
    AND prod_id.id_number=produkt.prodult_id
here;
        
        return DB::query(Database::SELECT, $sql)
                   ->execute();
    }
    
    
    
    
    
    
    
    
    
    public function getProduct($id = '')
    {
               
        $sql=<<<here
SELECT 
        produkt.id AS id,
        produkt.produkt_name AS name,
        produkt.product_price AS price,
        catalog_id.catalog AS catalog,
        company_id.company_name AS company,
        id_about.about AS about,
        prod_id.product_name AS prodgroup

        
FROM 
        produkt,
        catalog_id,
        company_id,
        id_about,
        prod_id
         
        

WHERE 
        catalog_id.id_number =produkt.catalog_id
    AND company_id.id_number=produkt.company_id
    AND id_about.id_number=produkt.id
    AND prod_id.id_number=produkt.prodult_id
    AND produkt.id= :id        
here;
        
        $query = DB::query(Database::SELECT, $sql, FALSE)
                         ->param(':id', (int)$id)
                         ->execute();
 
        $result = $query->as_array();
 
        if($result)
            return $result[0];
        else
            return FALSE;
    }

    

    
    
    public function getProdGroups()
    {
               
        $sql=<<<here
SELECT * FROM prod_id
here;
        
        return DB::query(Database::SELECT, $sql)
                   ->execute();
    }  
    
    
    
    public function getProductsInProdGroup($prodgroup = '')
    {
               
        $sql=<<<here
SELECT 
        produkt.id AS id,
        produkt.produkt_name AS name,
        produkt.product_price AS price,
        catalog_id.catalog AS catalog,
        company_id.company_name AS company,
        id_about.about AS about,
        prod_id.product_name AS prodgroup

        
FROM 
        produkt,
        catalog_id,
        company_id,
        id_about,
        prod_id
         
        

WHERE 
        catalog_id.id_number =produkt.catalog_id
    AND company_id.id_number=produkt.company_id
    AND id_about.id_number=produkt.id
    AND prod_id.id_number=produkt.prodult_id
    AND prod_id.product_name= :prodgroup
         
here;
        
        return DB::query(Database::SELECT, $sql)
                         ->param(':prodgroup', $prodgroup)
                          ->execute();
    }  
    
    
 
    
    
    
    public function getProductsInProdSubGroup($prodgroup = '',$subGroup='')
    {
               
        $sql=<<<here
SELECT 
        produkt.id AS id,
        produkt.produkt_name AS name,
        produkt.product_price AS price,
        catalog_id.catalog AS catalog,
        company_id.company_name AS company,
        id_about.about AS about,
        prod_id.product_name AS prodgroup

        
FROM 
        produkt,
        catalog_id,
        company_id,
        id_about,
        prod_id
         
        

WHERE 
        catalog_id.id_number =produkt.catalog_id
    AND company_id.id_number=produkt.company_id
    AND id_about.id_number=produkt.id
    AND prod_id.id_number=produkt.prodult_id
    AND prod_id.product_name= :prodgroup
    AND catalog_id.catalog= :subGroup     
here;
        
        return DB::query(Database::SELECT, $sql)
                         ->param(':prodgroup', $prodgroup)
                         ->param(':subGroup', $subGroup)
                         ->execute();
    }
    
    
    
    
    
    
    
    
    
    
   public function getSubGroup($prodGroup)
    {
               
        $sql=<<<here
SELECT * FROM catalog_id
WHERE  prodGroup=:prodGroup        
here;
        
        return DB::query(Database::SELECT, $sql)
                   ->param(':prodGroup', $prodGroup)
                   ->execute();
    } 
    
    
    
    
}

 